<%
function currentPageUrl()    
    Dim b,c,d
    b=Request.ServerVariables("SCRIPT_NAME")
    c=Request.ServerVariables("QUERY_STRING")
    d=b&"?"&c
    if InStrRev(d,"/")<>"" then
        d=Right(d,(Len(d)-(InStrRev(d,"/"))))
    end If      
    d=Replace(d,"&","") 
    currentPageUrl=d
End function

Function FiltrateHtmlMark(str) 
        str=Left(str,400)
        str=FiltrateUBBMark(str)
        str=ReplaceStr(str)                             
        Dim positionA,positionB
        positionA=instr(str,"<")
        positionB=instr(str,">")
        If positionA<>0 and positionB<>0 then
              Dim str1,str2,str3   
              str1=Left(str,positionA-1)
              str2=Right(str,Len(str)-positionB)
              If str2<>"" then
                     str3=str1 & str2
              Else
                     str3=str1   
              End If 
               if Left(str3,1)="" then
                     str3=right(str3,Len(str3)-1)
               end if
                str3=FiltrateHtmlMark(str3)
                str3=Left(str3,20)
                FiltrateHtmlMark=str3 
        Else
                str=Replace(str,"&lt;","")
                str=Replace(str,"&gt;","")
              str=Left(str,20)
              FiltrateHtmlMark=str
        End If 
End Function

Function FiltrateUBBMark(str)
        Dim positionA,positionB
        positionA=instr(str,"[")
        positionB=instr(str,"]")
        If positionA<>0 and positionB<>0 then
            Dim str1,str2,str3   
            str1=Left(str,positionA-1)
            str2=Right(str,Len(str)-positionB)
            str3=str1 & str2
            str3=FiltrateUBBMark(str3)
            FiltrateUBBMark=str3
        Else
            FiltrateUBBMark=str   		
        End If 
End Function

Function ReplaceStr(str) 
       str=Replace(str,"&lt;","<")
       str=Replace(str,"&gt;",">")
       ReplaceStr=str
End Function

function htmlencode(str)
    dim result
    dim l
    if isNULL(str) then 
       htmlencode2=""
       exit function
    end if
    l=len(str)
    result=""
	dim i
	for i = 1 to l
	    select case mid(str,i,1)
	           case "<"
	                result=result+"&lt;"
	           case ">"
	                result=result+"&gt;"
              case chr(13)
	                result=result+"<br>"
	           case chr(34)
	                result=result+"&quot;"
	           case "&"
	                result=result+"&amp;"
              case chr(32)	           
	                if i+1<=l and i-1>0 then
	                   if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9)  then	                      
	                      result=result+"&nbsp;"
	                   else
	                      result=result+" "
	                   end if
	                else
	                   result=result+"&nbsp;"	                    
	                end if
	           case chr(9)
	                result=result+"    "
	           case else
	                result=result+mid(str,i,1)
         end select
       next 
       result=replace(result,"&lt;","<")
       result=replace(result,"&gt;",">")
       htmlencode=result
end function

Function myReplace(myString)
	myString=Replace(myString,"&","&amp;")
	myString=Replace(myString,"<","&lt;")
	myString=Replace(myString,">","&gt;")
	myString=Replace(myString,chr(13),"<br>")
	myString=Replace(myString,chr(32),"&nbsp;")
	myString=Replace(myString,chr(9)," &nbsp; &nbsp; &nbsp; &nbsp;")
	myString=Replace(myString,chr(39),"&acute;")
	myString=Replace(myString,chr(34),"&quot;")
	myReplace=myString
End Function

Function myReplace_not(myString)
	myString=Replace(myString,"&amp;","&")
	myString=Replace(myString,"&lt;","<")
	myString=Replace(myString,"&gt;",">")
	myString=Replace(myString,"<br>",chr(13))
	myString=Replace(myString,"&nbsp;",chr(32))
	myString=Replace(myString," &nbsp; &nbsp; &nbsp; &nbsp;",chr(9))
	myString=Replace(myString,"&acute;",chr(39))
	myString=Replace(myString,"&quot;",chr(34))
	myReplace_not=myString
End Function

Function GetSafeStr(str)
	GetSafeStr = Replace(Replace(Replace(Trim(str), "'", ""), Chr(34), ""), ";", "")
End Function

Function FiltraterChar(myString)
        FiltraterChar = Replace(Replace(Replace(Replace(Replace(Trim(myString), "'", ""), Chr(34), ""), ";", ""),"<", ""),">", "")
End Function

Function replaceChr32(isCharacter)
    replaceChr32=Replace(isCharacter,chr(32),"")
End Function 

Function replaceChr32_2(isCharacter)
    replaceChr32_2=Replace(isCharacter,"",chr(32))
End Function 

function urldecode(encodestr) 
    newstr="" 
    havechar=false 
    lastchar="" 
    for i=1 to len(encodestr) 
       char_c=mid(encodestr,i,1) 
       if char_c="+" then 
            newstr=newstr & " " 
       elseif char_c="%" then 
            next_1_c=mid(encodestr,i+1,2) 
            next_1_num=cint("&H" & next_1_c) 
            if havechar then 
                havechar=false 
                newstr=newstr & chr(cint("&H" & lastchar & next_1_c)) 
            else 
                if abs(next_1_num)<=127 then 
                    newstr=newstr & chr(next_1_num) 
                else 
                    havechar=true 
                    lastchar=next_1_c 
                end if 
            end if 
            i=i+2 
        else 
            newstr=newstr & char_c 
        end if 
    next 
    urldecode=newstr 
end Function


Function FileContentSize(aaa)
       Dim aSavePathFileName
        aSavePathFileName = Split(aaa, "|")
        Dim i,bbb,dddd
        dddd=0
        For i = 0 To UBound(aSavePathFileName)
               bbb = aSavePathFilename(i)
                Dim backFileName
                backFileName = Split(bbb, "/")
                Dim i2,bbb2
                For i2 = UBound(backFileName) To UBound(backFileName)
                       bbb2 = backFileName(i2)
                Next
                dim fso,d,fc,f,drvpath,fsofile		
                set fso=server.createobject("scripting.filesystemobject")
                drvpath=server.mappath(".\")
                       if fso.FileExists(drvpath & "\eWebEditor/uploadfile\" & bbb2)=true Then
	           set d=fso.getfile(drvpath & "/ewebeditor/uploadfile/" & bbb2) 
                             dim dsize
                             dsize=d.size
                             set d=nothing   
                       end if
                set fso=nothing   
                dddd=dddd +dsize
        Next
        FileContentSize=dddd
End Function

Function FileContentSize2(aaa)
                           dim size,showsize
	         size=aaa
	         showsize=size & "<font color='#000000'>B</font>"      '   &nbsp;Byte"
	         if size>1024 then
	              size=(size\1024)
	              showsize=size & "<font color='#000000'>KB</font>"
	         end if
	         if size>1024 then
	              size=(size/1024)
	              showsize=formatnumber(size,2) & "<font color='red'>MB</font>"		
	         end if
	         if size>1024 then
	              size=(size/1024)
	              showsize=formatnumber(size,2) & "<font color='red'>GB</font>"	   
	         end if   
                          FileContentSize2=showsize 
End Function

Function UserScore(aaa)
      dim rs,sql,aaa2
      sql="select * from MYScoreRoom"
      set rs=conn.execute(sql)
            aaa2=rs(aaa)
       rs.close
       set rs=nothing
       UserScore = aaa2
End Function

function MyUserIntegral(aaa)
        dim rs,spl,UserIntegral2
         Set rs=server.createobject("ADODB.RECORDSET")
         sql="SELECT UserIntegral FROM ts_userinfo where username='"&aaa&"'"
         rs.open sql,conn
             if not rs.eof then			  
                    UserIntegral2=rs("UserIntegral")
             end if
         rs.close
         set rs=nothing
         MyUserIntegral = UserIntegral2
end function

function starGrade(user)
     dim rs,sql,number,t11
     sql="select UserIntegral from ts_userinfo where username='"&user&"'"   
     rs=conn.execute(sql)
          number=rs("UserIntegral")
          if number<10 then
                 t11="()"
          elseif number>=10 and number<100 then
                 t11= "<font color=red size=1></font>"
          elseif number>=100 and number<200 then
                 t11= "<font color=red size=1></font>"
          elseif number>=200 and number<300 then
                 t11= "<font color=red size=1></font>"
          else
                 t11= "<font color=red size=1></font>"
          end if
     starGrade=t11
end function

function showlistok()
        dim SQL,RS
        SQL = "SELECT showlist FROM option1"
        Set RS = Server.CreateObject("ADODB.Recordset")
               RS.Open SQL, Conn
                       showlistok = RS("showlist")
               RS.close
         Set RS=nothing
end function

function Community_Count()
        dim rs,sql
        Dim C_Count
        If session("tslt_useridentity")=1 or session("tslt_useridentity")=2 Then 
            sql="SELECT count(id) as C_Count FROM community"
        Else
            If session("tslt_useridentity")=0 And authUser()=False Then
                sql="select count(id) as C_Count from community where allAAH=false and autSelBoard=false and CommunityHidden=false"
            ElseIf authUser() Then 
                sql="select count(id) as C_Count from community where autSelBoard=false and CommunityHidden=false"
            Else 
                sql="select count(id) as C_Count from community where CommunityHidden=false"
	        End If 
        End If
        set rs=conn.execute(sql) 
            Dim n 
            n = 1
            If rs("C_Count")<>0 Then
	            n = n + rs("C_Count")
            Else 
                n = 1
		    End If 
        rs.close
        set rs=nothing
        Community_Count = n
end function

function CBoard_Count(aaa)
         dim rs,sql
        Dim C_B_Count
         If session("tslt_useridentity")=1 or session("tslt_useridentity")=2 Then 
             sql="SELECT count(boardid) as C_B_Count FROM board where Communityid=" &aaa
	     ElseIf session("tslt_useridentity")=3 Then
             sql="SELECT count(boardid) as C_B_Count FROM board where boardhidden=false and Communityid= " &aaa
		 ElseIf authUser() Then 
             sql="SELECT count(boardid) as C_B_Count FROM board where autSel=false and boardhidden=false and Communityid= " &aaa
         Else
             sql="SELECT count(boardid) as C_B_Count FROM board where autSel=false and authentication=false and boardhidden=false and Communityid= " &aaa             
         End If  
         set rs=conn.execute(sql)
             Dim n 
             n = 1
             If rs("C_B_Count")<>0 Then
	             n = n + rs("C_B_Count")
             Else 
                 n = 1
		     End If 
         rs.close
        set rs=nothing
        CBoard_Count = n
end function

function board_BZUser(aaa)
    board_BZUser=false
    dim rs,sql
    sql="select username from admin where boardid="&aaa
    set rs=conn.execute(sql) 
        do while not rs.eof
            if rs("username")=session("tslt_username") then
                board_BZUser=True
                Exit Function
            end if
            rs.movenext
        loop
    rs.close
    set rs=nothing
end function

Function authUser()
      dim rs,ql
      authUser=False
      sql="select username from ts_userinfo where aueUser=true and bclass=0"   
      set rs=conn.execute(sql)
             do while not rs.eof
                   if rs("username")=session("tslt_username") then
                         authUser=True 
                         Exit Function 
                   end if
                   rs.movenext
             loop
       rs.close
       set rs=Nothing
End Function

function NewRH(aaa)
       dim rs,spl,i
       set rs = Server.CreateObject("ADODB.Recordset")
       sql="select reply_human from reply where Cstr(reply_id)='"&aaa&"'"
       rs.open sql,conn
            if not rs.EOF then
                  for i=1 to 1
                       NewRH = rs("reply_human")
                       rs.movenext
	     If rs.EOF Then Exit For
                  next
            end if
       rs.close 
       set rs=nothing 
end function

function MySI()
        dim rs,Sql                  
        Sql = "select SubmitInterval from option1"
        set rs=conn.execute(Sql)
              MySI=rs("SubmitInterval")
         rs.close
         set rs=nothing
end function

Function boardname(aaa)
    dim SQL,RS
    SQL = "SELECT boardname FROM board where cstr(boardid)='" & aaa &"'"
    set RS=conn.execute(SQL)
            boardname= RS("boardname")
    RS.close
    set RS=nothing
End Function

Function ArticleBoardid(aaa)	
    dim rs,Sql,boardid
    Set rs = Server.CreateObject("ADODB.Recordset")                          
    Sql = "Select boardid from article where ID =" & aaa
    rs.Open Sql, conn     
        if not rs.eof then                     
            boardid = rs("boardid")                  
        end if
    rs.close
    set rs=nothing
    ArticleBoardid = boardid
End Function

Function Communityid_B_boardid(aaa)
    dim SQL,RS
    SQL = "SELECT Communityid FROM board where cstr(boardid)='" & aaa &"'"
    set RS=conn.execute(SQL)
            Communityid_B_boardid= RS("Communityid")
    RS.close
    set RS=nothing
End Function

Function Communityname(aaa) 
    dim SQL,RS
    SQL = "SELECT CommunityName FROM community where cstr(id)='" & aaa &"'"
    set RS=conn.execute(SQL)
            Communityname= RS("CommunityName")
    RS.close
    set RS=nothing
End Function

function replyList2(aaaa)
       dim ReplyRS,replyimg
       replyimg=true
       set ReplyRS = Server.CreateObject("ADODB.Recordset")
       ' Replysql="select * from reply where Cstr(reply_id)='"&aaaa&"' order by id Asc"
       Replysql="select id from reply where Cstr(reply_id)='"&aaaa&"'"
       Replyrs.open Replysql,conn
            if Replyrs.EOF or Replyrs.bof then
                   replyimg=false
             end if
        Replyrs.close 
       set Replyrs=nothing 
       replyList2=replyimg
end function

Function DemoLinkYesNo()
    dim SQL,RS
    SQL = "SELECT DemoLink FROM option1"
	set RS = conn.execute(SQL)
        DemoLinkYesNo = RS("DemoLink")
    RS.close
    set RS = nothing
End Function

function MyFriend(mfo)  
          dim MyFrienOnline
          MyFrienOnline = false
          if session("tslt_username")<>"" then
                 dim rs,self,self2
                 set rs=conn.execute("select friend from ts_userinfo where username='"&session("tslt_username")&"'")
                       do while not rs.eof
                             if RS("friend")<>"" then
                                    self = RS("friend")
                                    self2 = Split(self,"|")
                                    Dim i
                                    For i = UBound(self2) To 0 step-1
                                           if self2(i) = mfo then 
                                                 MyFrienOnline = true   
                                           end if                  
                                    Next
                             end if
                             rs.movenext
                       loop
                 rs.close
                 set rs=nothing
          end if
          MyFriend = MyFrienOnline
end function

Function isCEBM()
    dim SQL,RS
    SQL = "SELECT CEBM FROM option1"
	set RS = conn.execute(SQL)
        isCEBM = RS("CEBM")
    RS.close
    set RS = Nothing
End Function

Function isTotalPage(id)
       Dim rs,sql
       Set rs = Server.CreateObject("ADODB.Recordset")
       sql="select id from reply where Cstr(reply_id)='"&id&"'"
       rs.open sql,conn,1,1
           if NOT (rs.EOF And rs.BOF) Then
               rs.pagesize=showlistok()
               isTotalPage=rs.pagecount
           end If
       rs.close
       set rs=nothing 
End Function 

Function isTotalRecordcount(id)
       Dim rs,sql
       Set rs = Server.CreateObject("ADODB.Recordset")
       sql="select id from reply where Cstr(reply_id)='"&id&"'"
       rs.open sql,conn,1,1
           if NOT (rs.EOF And rs.BOF) Then
               isTotalRecordcount=rs.recordcount
           end If
       rs.close
       set rs=nothing 
End Function 

Function userIP()  
        userIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
        If userIP = "" Then userIP = Request.ServerVariables("REMOTE_ADDR") 
End Function

' -----------------------------------------------------------
Function boardmanageuser_yes(isBoardId)
    boardmanageuser_yes= False 
    Dim sql,rs
    sql="select id from admin where boardid="&isBoardId
    Set rs=conn.execute(sql)
        If Not(rs.eof And rs.bof) Then
             boardmanageuser_yes=True 
        End If 
    rs.close
    Set rs=Nothing  
End Function

Function boardAT(boa)
	Dim Rs,Sql
    Set Rs = server.CreateObject("adodb.recordset")
    Sql = "select id FROM article where boardid="&boa
    Rs.open Sql,conn,1,1
        If  Not(Rs.Eof And Rs.bof) Then 
            boardAT = Rs.Recordcount
		Else
		    boardAT = 0
        End If 
    Rs.Close
    Set Rs = Nothing
End Function

Function boardRAT(boa)
	Dim Rs,Sql
    Set Rs = server.CreateObject("adodb.recordset")
    Sql = "select id FROM article where boardid="&boa
    Rs.open Sql,conn,1,1
	    Dim i
		i = 0
        DO WHILE NOT rs.EOF

            Dim ReplyRS,ReplySql
            Dim replyAC
            Dim n
            n=0
	        ReplySql="select count(id) as replyAC from reply where Cstr(reply_id)='"&Rs("id")&"'"
            Set Replyrs = conn.execute(ReplySql)
                If Replyrs("replyAC")<>0 Then
	                n = Replyrs("replyAC")
                Else 
                    n = 0
		        End If 
            Replyrs.close 
            Set Replyrs=Nothing 
            i = i+n
            rs.movenext        
        Loop
    Rs.Close
    Set Rs = Nothing
	If i="" Then i=0
    boardRAT = i
End Function

Function resArrKeyword(sel1,keyword2)
    If sel1="" Then
	    sel1="subject"
	ElseIf sel1="" Then
	    sel1="Content"
    End If 
    Dim arrKeyword,numKeyword,condition
    arrKeyword=Split(keyword2," ")      
	numKeyword=Ubound(arrkeyword)
	condition=sel1 & " like '%" & arrKeyword(0) & "%'"
	For I=1 To numKeyword
	    condition=condition & " And " & sel1 & " like '%" & arrKeyword(I) & "%'"
	Next
    resArrKeyword=condition
End Function 

Function boardARSize(boardId)
       dim rs,Sql,ss
       ss = 0
       Set rs = Server.CreateObject("ADODB.Recordset")
       Sql = "Select * from article where boardid = " &boardId
       rs.Open Sql,conn                   
                DO WHILE NOT rs.EOF                    
                       ss = ss + rs("contentsize") + rs("AllReplySize")        
                       rs.movenext    
                 loop             
        rs.close
        set rs=Nothing
        ss = FileContentSize2(ss)
        boardARSize = ss        
End Function 

Function TTCount()
    Dim rs,sql
	Sql = "select TempTopCount from option1"
    Set rs=conn.execute(Sql)
        TTCount=rs("TempTopCount")
    rs.close
    Set rs=Nothing
End Function 

function isboardid(boardidid)
       dim rs
       set rs=conn.execute("select boardid from article where id="&boardidid)
       if rs("boardid")<>"" then
              isboardid=rs("boardid")
       end if
       rs.close
       set rs=nothing
end function

function islockarticle(aid)
        islockarticle=false
       dim rs
       set rs=conn.execute("select lockarticle from article where id="&aid)
           if rs("lockarticle")=true then
                islockarticle=true
           end if
       rs.close
       set rs=nothing
end Function

Function isBoardReadonly(aaa)
    dim SQL,RS
    SQL = "SELECT boardreadonly FROM board where cstr(boardid)='" & aaa &"'"
    set RS = conn.execute(SQL)
        isBoardReadonly = RS("boardreadonly")
    RS.close
    set RS = Nothing
End Function

function boardmanageuser2(aaa)
        boardmanageuser2=false
       dim sql,rs
       sql="select mark,username from admin where boardid="&aaa
       set rs=conn.execute(sql)
                   do while not rs.eof
                           if rs("mark")=true then
                                 if session("tslt_username")=rs("username") then
                                        boardmanageuser2=true
                                 end if
                            end if
                            rs.movenext
                    loop
        rs.close
        set rs=nothing 
end function

Function CommunityHiddenYesNo(aaa)
    dim SQL,RS
    SQL = "SELECT CommunityHidden FROM community where cstr(id)='" & aaa &"'"
	set RS = conn.execute(SQL)
        CommunityHiddenYesNo = RS("CommunityHidden")
    RS.close
    set RS = nothing
End Function

' -----------------------------------------------------------
function VCYes()
    dim rs,Sql                  
    Sql = "select * from option1"
    set rs=conn.execute(Sql)
        VCYes=rs("ValidateCode")
    rs.close
    set rs=nothing
end function

function LoginYesNo()
    dim rs,Sql                  
    Sql = "select LoginYes from option1"
    set rs=conn.execute(Sql)
        LoginYesNo=rs("LoginYes")
    rs.close
    set rs=nothing
end function

function IsEWebYesNo()
    dim rs,Sql                  
    Sql = "select IsEWeb from option1"
    set rs=conn.execute(Sql)
        IsEWebYesNo=rs("IsEWeb")
    rs.close
    set rs=nothing
end function

%>